<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
//
//
//// ^2_3^ 路由定义
use think\facade\Route;
//
Route::get('think', function () {
    //// 抛出
    //throw new \think\exception\ValidateException('ValidateException异常');

    //// app路径
    //dump( \think\facade\App::getAppPath() );

    return 'hello,ThinkPHP6!';
});
//
Route::get('hello/:name', 'index/hello');
//
//// 触发事件
Route::get('/event/trigger', function () {
    \think\facade\Event::trigger('DemoEvent', 'cyb');
});
//
//// 模型
Route::get('/model/data', function() {
    $data = [
        'title' => "title_".time()
    ];
    $postsAdd = new \app\model\DemoPosts();
    $postsAdd->save($data);

    $posts = \app\model\DemoPosts::select();

    return $posts;
});
//
//// 日志
Route::get('/log', function(\app\Request $request) {
    // 日志级别
    // 从低到高依次为：debug, info, notice, warning, error, critical, alert, emergency。额外sql日志级别。

    // 记录日志信息到内存(请求结束后会写入)
    \think\facade\Log::record('记录日志信息到内存(请求结束后会写入)');

    // 实时写入
    \think\facade\Log::write('实时写入日志');

    return '日志记录';
});
